package com.codingman.springdemo5;

import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

public class Demo1 {
	public static void main(String[] args) {
		ExpressionParser parser = new SpelExpressionParser();

		Expression exp1 = parser.parseExpression("'Hello SPEL'");
		String message1 = (String) exp1.getValue();
		System.out.println(message1);

		Expression exp2 = parser.parseExpression("'Welcome SPEL'.concat('!')");
		String message2 = (String) exp2.getValue();
		System.out.println(message2);

		Expression exp3 = parser.parseExpression("'Hello World'.bytes");
		byte[] bytes = (byte[]) exp3.getValue();
		for (int i = 0; i < bytes.length; i++) {
			System.out.print(bytes[i] + " ");
		}
		System.out.println("");

		Expression exp4 = parser.parseExpression("'Hello World'.bytes.length");
		int length = (Integer) exp4.getValue();
		System.out.println(length);
		
		Expression exp5 = parser.parseExpression("new String('hello world').toUpperCase()");  
		String message5 = exp5.getValue(String.class);  
		System.out.println(message5); 
	}
}
